module cl {
	export class AttackEffect {
		public static shake(obj : egret.DisplayObject, radius : number, wait : number, time : number, shake_times : number = 6) : void {
			let xori = obj.x;
			let yori = obj.y;
			let gap = time / (shake_times + 2);

			let rads : number[] = [];
			let cur = 0;
			for (let i = 0; i < shake_times; i++) {
				cur = cur + (Math.random() + 0.5) * Math.PI;
				if (cur > Math.PI) {
					cur -= 2 * Math.PI;
				}
				rads.push(cur);
			}
			let animationHandle = egret.Tween.get(obj).wait(wait);
			for (let i = 0; i < shake_times; i++) {
				animationHandle = animationHandle.to(Util.coordRadOffset(xori, yori, rads[i], radius), gap);
			}
			animationHandle.to({x : xori, y : yori}, gap);
		}

		public static attack(obj : egret.DisplayObject, degree : number, radius : number, wait : number, time : number) : void {
			let xori = obj.x;
			let yori = obj.y;
			let gap = time / 2;
			egret.Tween.get(obj).wait(wait).to(Util.coordDegreeOffset(xori, yori, degree, radius), gap)
					.to({x : xori, y : yori}, gap);
		}

		public static die(obj : egret.DisplayObject, time : number) : void {
			let coord = new Coord(obj.x, obj.y);
			let parent = obj.parent;
			parent.removeChild(obj);

			let missSymbol = Util.setImageCoord("miss_png", coord);
			parent.addChild(missSymbol);
			setTimeout(()=>{
				missSymbol.parent.removeChild(missSymbol);
			}, time);
		}
	}
}